//
//  RootTabController.m
//  GIFShow
//
//  Created by lanou11air029 on 15/3/27.
//  Copyright (c) 2015年 CK. All rights reserved.
//

#import "RootTabController.h"
#import "FirstNavigationController.h"
#import "FirstViewController.h"
#import "GifController.h"
#import "GifNavigationController.h"
#import "ClassesNavigationController.h"
#import "ClassesVC.h"
#import "UserNavigationController.h"
#import "UserSettingController.h"
#import "MySettingOptions.h"
#import <AFNetworking/AFNetworking.h>
@interface RootTabController ()

@end

@implementation RootTabController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.hidesBottomBarWhenPushed = YES;
    self.tabBar.tintColor = [UIColor redColor];
    FirstViewController * firstVC = [[FirstViewController alloc]init];
    GifController * gifVC = [[GifController alloc]initWithStyle:UITableViewStylePlain Url:@"http://gif.duowan.com/index.php?r=gif/topicList&page=1&pageSize=30"];
    ClassesVC * classesVC = [[ClassesVC alloc]init];
    self.tabBar.clipsToBounds = YES;
    classesVC.urlStr = @"http://gif.duowan.com/index.php?r=gif/labelList&page=1&pageSize=30";
    UserSettingController * userSC = [[UserSettingController alloc]initWithStyle:UITableViewStylePlain];
    
    
    
    GifNavigationController * gifNVC = [[GifNavigationController alloc]initWithRootViewController:gifVC];
    ClassesNavigationController * classesNVC = [[ClassesNavigationController alloc]initWithRootViewController:classesVC];
    UserNavigationController * userNVC = [[UserNavigationController alloc]initWithRootViewController:userSC];
    FirstNavigationController * firstNC = [[FirstNavigationController alloc]initWithRootViewController:firstVC];

    [self addChildViewController:firstNC];
    [self addChildViewController:gifNVC];
    [self addChildViewController:classesNVC];
    [self addChildViewController:userNVC];
    
    firstNC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"段子" image:[UIImage imageNamed:@"content.png"] selectedImage:nil];
    gifNVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"热门Gif" image:[UIImage imageNamed:@"hot"]  selectedImage:nil];
    classesNVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"分类" image:[UIImage imageNamed:@"class.png"] selectedImage:nil];
    userNVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我" image:[UIImage imageNamed:@"user"] selectedImage:nil];
    
    [self setupTitleViewWithImageNamed:@"hotTitle.png" ToViewController:gifVC];
    [self setupTitleViewWithImageNamed:@"palace.png" ToViewController:classesVC];
    [self setupTitleViewWithImageNamed:@"mine.png" ToViewController:userSC];

    
  

    self.viewControllers = @[firstNC,gifNVC,classesNVC,userNVC];
    self.selectedIndex = 1;
    // Do any additional setup after loading the view.
    
    [self myTheme];
    [[NSNotificationCenter defaultCenter]addObserverForName:@"ChangeTheme" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        [self myTheme];
    }];
}
-(void)myTheme{
    NSString * file = [MySettingOptions defaultOptions].backColor;
    NSString * name = [NSString stringWithFormat:@"%@tab",file];
    [self.tabBar setBackgroundImage:[UIImage imageNamed:name]];

    if ([name isEqualToString:@"back01"]) {
        [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
    }
    if ([name isEqualToString:@"back01"]) {
        [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
    }
    if ([name isEqualToString:@"back01"]) {
        [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
    }
    if ([name isEqualToString:@"back01"]) {
        [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
    }
}
-(void)setupTitleViewWithImageNamed:(NSString *)imageName ToViewController:(UIViewController *)viewController{
    UIImageView * titleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 120, 25)];
    titleImageView.image = [UIImage imageNamed:imageName];
    [viewController.navigationItem setTitleView:titleImageView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
